<?php

use common\lib\defaultHtml;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Employees');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="users-index">

    <p>
        <?= defaultHtml::a(Yii::t('app', 'Create Icon'), ['create'], ['class' => 'btn btn-sm btn-success']) ?>
    </p>


    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            
            'id',
            'username',
            ['attribute' => 'limitStr', 'value' => function($model){
                switch($model->limitStr){
                    case 'init':
                        return '创始人';
                    break;
                    case 'employee':
                        return '普通员工';
                    break;
                    case 'manager':
                        return '管理员';
                    break;
                    case '':
                        return '创始人';
                    break;
                }
            }],
            ['attribute' => 'status', 'value' => function($model){
                switch($model->status){
                    case 10:
                        return '<span class="text-success">已启用</span>';
                    break;
                    case 11:
                        return '<span class="text-danger">已禁用</span>';
                    break;
                }
            }, 'format' => 'html'],
            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '<div class="text-center">操作</div>',
                'template' => '<div class="btn-group">{update}{forbidden}</div>',
                'buttons' => [
                    'update' => function ($url, $model, $key) {
                        if($model->limitStr != 'init' && $model->limitStr != ''){
                            return defaultHtml::a('<span class="fa fa-pencil"></span> 更新', $url, ['title' => '更新', 'class' => 'btn btn-xs  btn-info']);
                        }
                    },
                    'forbidden' => function ($url, $model, $key) {
                        if($model->limitStr != 'init' && $model->limitStr != ''){
                            if($model->status == 10){
                                $btn = defaultHtml::a('<span class="fa fa-remove"></span> 禁用', $url, ['title' => '禁用', 'class' => 'btn btn-xs  btn-danger']);
                            }elseif($model->status = 11){
                                $btn = defaultHtml::a('<span class="fa fa-check"></span> 启用', $url, ['title' => '启用', 'class' => 'btn btn-xs  btn-success']);
                            }
                            return $btn;
                        }
                    },
                ],
                'headerOptions' => ['width' => '120'],
            ],
        ],
    ]); ?>


</div>
